﻿using AnyCAD.Foundation;
using AnyCAD.NX.Controls;
using AnyCAD.NX.View;
using AnyCAD.NX.ViewModel;
using Rapid.Sketch.Plugin.Model;
using Rapid.Sketch.Plugin.SectionBar;
using System.ComponentModel;
using System.Windows;

namespace Rapid.Sketch.Plugin.View
{
    /// <summary>
    /// SectionBarView.xaml 的交互逻辑
    /// </summary>
    public partial class SectionBarView : AuSubView
    {
        public SectionBarView(ShapeElement instance, SchemaComponent component, MainViewModel doc, PropertyChangedEventHandler callback)
        {
            InitializeComponent();
            this.DataContext = new SectionBarViewModel(instance, component, doc, callback);
        }
    }

    //定义属性界面创建方法
    public class SectionBarViewCreator : IPropertyViewCreator
    {
        public string Name { get => nameof(SectionBarModel); }

        public bool Create(IPropertyView container, PropertyViewCreatorArgs args, RenderViewModel mainViewModel)
        {
            var viewModel = mainViewModel as MainViewModel;
            if(viewModel == null)
            {
                return false;
            }

            var se = ShapeElement.Cast(args.Object as Element);
            if (se == null)
                return false;

            var component = SchemaComponent.Cast(se.GetComponent(nameof(SchemaComponent)));
            container.AddView(new SectionBarView(se, component, viewModel, args.EventHandler));

            return true;
        }
    }
}
